package com.cdn.plugin;

import com.cdn.plugin.consts.PluginStatus;
import com.cdn.plugin.consts.SysConst;
import com.cdn.plugin.depress.ClassPathDataCopier;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.execution.runners.JavaProgramPatcher;
import com.intellij.util.PathsList;

import java.nio.file.Paths;

import static com.cdn.plugin.consts.SysConst.*;


/**
 * 蔡定努
 * 2024/08/22 21:29
 */

public class JavaParameters extends JavaProgramPatcher {


    /**
     * 添加jVM参数
     * 第一种方式： agent方式
     * 第二种方式： 添加到classpath下
     * @param executor
     * @param configuration
     * @param javaParameters
     */
    @Override
    public void patchJavaParameters(Executor executor, RunProfile configuration, com.intellij.execution.configurations.JavaParameters javaParameters) {
        if (PluginStatus.get()) {
            String target = Paths.get(WORK_HOME.toString(), LIB, JAR_NAME).toString();
            new ClassPathDataCopier().copyData("/lib/".concat(JAR_NAME), target);

            // agent 添加参数
            // ParametersList vmParametersList = javaParameters.getVMParametersList();
            // vmParametersList.add("-javaagent:" + target);

            PathsList classPath = javaParameters.getClassPath();
            classPath.add(SysConst.LIB_PATH.toString());
        }
    }


}
